//
//  MyViewController.m
//  afn
//
//  Created by mac on 2018/5/7.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "MyViewController.h"
#import "SetUpViewController.h"
#import "MyView.h"
@interface MyViewController ()
@property(nonatomic,strong)MyView *aView;

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self wr_setNavBarBackgroundAlpha:0];
    self.navigationItem.title=@"个人中心";
    [self wr_setNavBarTintColor:[UIColor whiteColor]];
    [self wr_setNavBarTitleColor:[UIColor whiteColor]];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_shezhi"] style:UIBarButtonItemStylePlain target:self action:@selector(pushToSetUp)];
    
    _aView=[MyView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-TAB_BAR_HEIGHT);
    }];
    [_aView creatView];
    _aView.viewController=self;
    [self getData];
}

-(void)viewDidAppear:(BOOL)animated{
    [_aView.tableView  reloadData];
}
-(void)viewWillAppear:(BOOL)animated{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *token= [defaults objectForKey:@"token"];
    if ([gongju charIsNil:token]) {
        [gongju ToLoging:self];
    }
}
-(void)pushToSetUp{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *token= [defaults objectForKey:@"token"];
    if ([gongju charIsNil:token]) {
        [gongju ToLoging:self];
        return;
    }
    SetUpViewController *setUp=[[SetUpViewController alloc] init];
    [gongju pushNextViewController:self andRootController:setUp];
}

-(void)getData{
    [gongju AFNPOSTDataUrl:@"v1/user/user-center" andDic:nil andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        
        [NSKeyedArchiver archiveRootObject:responseObject toFile:_userModelFile];
        [self->_aView.tableView  reloadData];
        
    } anderrorBlock:nil];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
